package com.sdry.good.logistics.controller;

import com.sdry.basic.entity.Material;
import com.sdry.basic.service.MaterialService;
import com.sdry.common.BaseController;
import com.sdry.common.ResultAppInfo;
import com.sdry.common.TableDataInfo;
import com.sdry.good.logistics.entity.ReportDeficiencyOrderDetail;
import com.sdry.good.logistics.entity.ReportPicking;
import com.sdry.good.logistics.service.ReportPickingService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 领料清单
 * @author makejava
 * @date  2020-04-02 15:29:39
 * @version 1.0
 */
@Controller
@RequestMapping("reportPicking")
public class ReportPickingController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ReportPickingService reportPickingService;

    @Resource
    private MaterialService materialService;

    /**
     * 展示领料管理
     * @return
     */
    @RequestMapping(value = "showReportPicking")
    public String showReportPicking(Model model) {
        Material param = new Material();
        List<Material> materialList = materialService.queryAllByMution(param);
        model.addAttribute("materialList",materialList);
        model.addAttribute("System",System.currentTimeMillis());
        return "/td/logistics/reportPicKing";
    }

    /**
     * 手动生成领料单添加
     * @param quantity 数量
     * @param maIds 产品ID
     * @param remark1 时间
     * @return
     */
    @RequestMapping(value = "/addReportPickingManual")
    @ResponseBody
    public boolean addReportPickingManual(
            String quantity,
            String maIds,
            String remark1,
            String plNumber
    ){
        try {
            return reportPickingService.addReportPickingManual(quantity,maIds,remark1,plNumber);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 分页查询领料单
     * @return
     */
    @RequestMapping(value = "queryReportPickingPage")
    @ResponseBody
    public TableDataInfo queryReportPickingPage(ReportPicking reportPicking) {
        List<ReportPicking> reportPickingList = reportPickingService.queryReportPickingPage(reportPicking);
        Long total = reportPickingService.queryReportPickingTotal(reportPicking);
        return getDataTable(reportPickingList,total);
    }

    /**
     * 通过主键查询单条数据
     * @param picId 主键
     * @return 单条数据
     */
    @RequestMapping("delReportPicking/{picId}")
    @ResponseBody
    public Integer delReportPicking(@PathVariable Long picId) {
        return reportPickingService.delReportPicking(picId);
    }

    /**
     * 生成领料单
     * @param rdoId 报缺单id
     */
    @RequestMapping(value = "/addReportPicking")
    @ResponseBody
    public int addReportPicking(Long rdoId) {
        int effect = 0;
        try {
            reportPickingService.addReportPicking(rdoId);
            effect = 1;
        }catch (Exception e){
            e.printStackTrace();
        }
        return effect;
    }
}